package com.kuaiyin.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
import com.kuaiyin.enums.Status;
import com.kuaiyin.sampling.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Map;

/**
 * 测试用例表（assertions可选）
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName(value = "test_case", autoResultMap = true)
@Schema(name = "TestCase", description = "测试用例表（assertions可选）")
public class TestCase extends BaseEntity implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    @Schema(description = "用例ID")
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    @Schema(
            description = "用例名称（唯一）",
            example = "用户登录测试",
            requiredMode = Schema.RequiredMode.REQUIRED
    )
    private String name;

    @Schema(
            description = "关联请求ID（逻辑外键）",
            example = "123",
            requiredMode = Schema.RequiredMode.REQUIRED
    )
    private Long requestId;

    @Schema(description = "关联的环境类型")
    private String environmentType; // DEV, TEST, STAGING, PROD


    @Schema(description = "数据驱动参数（JSON数组）")
    @TableField(typeHandler = FastjsonTypeHandler.class)
    private Map<String, Object> dataDriven;

    @Schema(description = "前置脚本（如数据准备）")
    private String preScript;

    @Schema(description = "后置脚本（如数据库校验）")
    private String postScript;

    @Schema(
            description = "超时时间（秒，0表示不限制）",
            example = "30",
            defaultValue = "30"
    )
    private Integer timeout;

    @Schema(description = "断言规则（JSON数组，可选）")
    @TableField(typeHandler = FastjsonTypeHandler.class)
    private Map<String, Object> assertions;

    @Schema(
            description = "执行状态",
            allowableValues = {
                    "NOT_RUN", "PENDING", "RUNNING",
                    "SUCCESS", "FAILED", "TIMEOUT"
            },
            defaultValue = "NOT_RUN"
    )
    private String execStatus;

    @Schema(
            description = "最后一次执行开始时间",
            example = "2023-10-01T10:00:00"
    )
    private LocalDateTime lastRunTime;

    @Schema(description = "最后一次执行耗时（毫秒）")
    private Integer lastRunDuration;

    @Schema(description = "断言结果（SUCCESS/FAILED）")
    private String lastRunResult;


    @Schema(description = "状态：0-禁用 1-启用")
    private Status status;


}